package guda.talk.biz.common.util;


/**
 * 位标记
 * Created by well on 15/3/13.
 */
public class TagUtil {


    public static long addTag(Long value,Long tag) {
        if(value == null){
            return 0;
        }
        if(tag == null){
            return value;
        }
        if ((tag & (tag - 1)) != 0) {
            throw new IllegalArgumentException("tag必须为2的n次方");
        }
        return value | tag;
    }

    public static long removeTag(Long value,Long tag) {
        if(value == null){
            return 0;
        }
        if(tag == null){
            return value;
        }
        if ((tag & (tag - 1)) != 0) {
            throw new IllegalArgumentException("tag必须为2的n次方");
        }
        return value & (tag ^ Long.MAX_VALUE);
    }

    public static boolean contains(Long value,Long tag) {
        if(value == null || tag == null){
            return false;
        }
        return ((value & tag) == tag);
    }


}
